package com.useage.day03;

// 单例设计模式
public class Singleton {
	
/*
	private Singleton() {
		
	}
	
	private static Singleton single;
	
	static {
		single = new Singleton();
	}

	public static Singleton getInstance() {
		return single;
	}
*/	

	private static Singleton single;
	
	// 获取实例的方法
	//   synchronized 
	public static synchronized Singleton getInstance() {
		if (single == null) {
			single = new Singleton();
		}
		return single;
	}
}

//Singleton a = Singleton.getInstance();
//Singleton b = Singleton.getInstance();
//
//如果34行 和 35 同时执行呢？ 在多线程环境下
